<?php
class CurlWrapper {
	private static $CurlWrapper = null;
	private $curl;
	
	public static function getSource($url){
		if(self::$CurlWrapper === null){
			self::$CurlWrapper = new CurlWrapper();
		}
		self::$CurlWrapper->setUrl($url);
		return self::$CurlWrapper->execute();
	}
	
	public function __construct(){
		$this->curl = curl_init();
		$this->configCurl();
	}
	
	public function setUrl($url){
		curl_setopt($this->curl, CURLOPT_URL, $url);
	}
	
	public function execute(){
		$source = curl_exec($this->curl);
		$info = curl_getinfo($this->curl, CURLINFO_CONTENT_TYPE);
		if(substr($info, 0, 5) == 'image'){
			return true;
		}
		if(!$source){
			return false;
		}
		return $source;
	}
	
	private function configCurl(){
		$options = array(
            CURLOPT_HEADER => false,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_MAXREDIRS => 5,
            CURLOPT_TIMEOUT => 10,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_SSL_VERIFYHOST => false
        );
		curl_setopt_array($this->curl, $options);
	}
	
	public function __destruct(){
		curl_close($this->curl);
	}
}